package com.huike.web.controller.system;


import com.huike.clues.domain.Course;
import com.huike.clues.service.CoursesService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clues/course")
@RestController
public class CoursesController extends BaseController {

    @Autowired
    private CoursesService coursesService;

    //查询课程管理列表
    @PreAuthorize("@ss.hasAnyPermi('system:courses:list')")
    @GetMapping("/list")
    public TableDataInfo selectCourseByPage(Course course) {
        startPage();
        List<Course> list = coursesService.selectCourseByPage(course);
        return getDataTable(list);
    }

    //新增课程管理
    @PreAuthorize("@ss.hasAnyPermi('system:courses:add')")
    @PostMapping
    public AjaxResult addCourse(@RequestBody Course course) {
        return toAjax(coursesService.addCourse(course));
    }

    //修改课程管理
    @PreAuthorize("@ss.hasAnyPermi('system:courses:update')")
    @PutMapping
    public AjaxResult updateCourse(@RequestBody Course course) {
        return toAjax(coursesService.updateCourse(course));
    }

    //根据id查询
    @PreAuthorize("@ss.hasAnyPermi('system:courses:id')")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id) {
        return AjaxResult.success(coursesService.selectById(id));
    }

    //根据id批量删除
    @DeleteMapping("/{ids}")
    public AjaxResult deleteByIds(@PathVariable Long[] ids) {
        coursesService.deleteByIds(ids);
        return AjaxResult.success();
    }

    @GetMapping("/listselect")
    public AjaxResult listselect(@RequestParam Integer subject) {
      List<Course> courseId=  coursesService.listselect(subject);
        return AjaxResult.success(courseId);
    }


}
